import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";
import { Pagination, Image } from "element-ui";
import { Overlay, Uploader } from "vant";
import moment from "moment";
import { getPageTitle } from "@/utils/YgHooks";

// 引入样式
import "element-ui/lib/theme-chalk/index.css"; // element ui
import "bootstrap/dist/css/bootstrap.css"; // bootstrap
import "animate.css"; // animate
import "vant/lib/overlay/style"; // vant overlay
import "vant/lib/uploader/style"; // vant uploader

// 自定义组件
import YgHeader from "@/components/YgHeader.vue";
import YgInput from "@/components/YgInput.vue";
import YgBackground from "@/components/YgBackground.vue";
import YgUserCard from "@/components/YgUserCard.vue";
import YgRecommend from "@/components/YgRecommend.vue";
import YgTags from "@/components/YgTags.vue";
import YgCatalog from "@/components/YgCatalog.vue";
import YgFooter from "@/components/YgFooter.vue";
import YgEmpty from "@/components/YgEmpty.vue";

Vue.config.productionTip = false;

// 使用moment中文包
moment.locale("zh-cn");

// 挂载方法
Vue.prototype.$moment = moment;

// element ui
Vue.use(Pagination);
Vue.use(Image);

// vant
Vue.use(Overlay); // 遮罩
Vue.use(Uploader); // Uploader 文件上传

// 全局组件
Vue.component("yg-header", YgHeader);
Vue.component("yg-input", YgInput);
Vue.component("yg-background", YgBackground);
Vue.component("yg-usercard", YgUserCard);
Vue.component("yg-recommend", YgRecommend);
Vue.component("yg-tags", YgTags);
Vue.component("yg-catalog", YgCatalog);
Vue.component("yg-footer", YgFooter);
Vue.component("yg-empty", YgEmpty);

// 路由前置守卫
router.beforeEach((to, from, next) => {
  document.title = getPageTitle(
    to?.meta?.title,
    store.state.User.userInfo.name
  );
  next();
});
// 路由后置守卫
router.afterEach(() => {
  window.scrollTo(0, 0);
});

new Vue({
  router,
  store,
  render: (h) => h(App),
}).$mount("#app");
